<?php


declare (strict_types=1);

namespace app\middleware;


use app\BaseController;
use Closure;
use thans\jwt\facade\JWTAuth;
use think\Request;

class Login extends BaseController
{
	/**
	 * 处理请求
	 *
	 * @param Request $request
	 * @param Closure $next
	 * @return mixed
	 */
	public function handle(Request $request, Closure $next)
	{
		if ($request->user_id == 0) {
			$this->writeJson(401, '请先登录');
		}
		
		$payload = JWTAuth::getPayload();
	
		if (isset($payload['user_status'])) {
			switch ($payload['user_status']){
				case 102:
					$this->writeJson(102, '请先绑定微信.');
				case 103:
					$this->writeJson(103, '请先绑定手机号.');
				case 104:
					$this->writeJson(104, '请先绑定小程序.');
				case 105:
					$this->writeJson(105, '请先完善资料.');
				case 106:
					$this->writeJson(106, '请先填写幸福感问卷调查.');
				case 107:
					$this->writeJson(107, '请先填写生活方式问卷调查.');
			}
		}
		return $next($request);
	}
}
